import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      name: '首页',
      path: '/',
      component: () => import('@/views/home/index.vue'),
      redirect: '/home',
      children: [
        {
          name: '主页展示',
          path: '/home',
          component: () => import('@/views/home/home.vue'),
          meta: {
            title: "ButVan's 博客"
          }
        },
        {
          name: '文章',
          path: '/article',
          component: () => import('@/views/article/index.vue'),
          meta: {
            title: '文章'
          }
        },
        {
          name: '随记',
          path: '/notes',
          component: () => import('@/views/notes/index.vue'),
          meta: {
            title: '随记'
          }
        },
        {
          name: '留言墙',
          path: '/wall',
          component: () => import('@/views/wall/index.vue'),
          meta: {
            title: '留言墙'
          }
        },
        {
          name: '相册',
          path: '/album',
          component: () => import('@/views/album/index.vue'),
          meta: {
            title: '相册'
          }
        },
        {
          name: '关于我',
          path: '/aboutme',
          component: () => import('@/views/aboutMe/index.vue'),
          meta: {
            title: '关于我'
          }
        },
        {
          name: '/友链',
          path: '/friend',
          component: () => import('@/views/friend/index.vue'),
          meta: {
            title: '友链'
          }
        },
        {
          name: '文章详情',
          path: '/article/:id',
          component: () => import('@/views/detail/ArticleDetail.vue'),
          meta: {
            title: '文章'
          }
        },
        {
          name: '动态详情',
          path: '/note/:id',
          component: () => import('@/views/detail/NoteDetail.vue'),
          meta: {
            title: '动态'
          }
        },
        {
          name: '/项目详情',
          path: '/project/:id',
          component: () => import('@/views/detail/ProjectDetail.vue'),
          meta: {
            title: '项目'
          }
        }
      ],
    },
    {
      name: '自我介绍',
      path: '/introduction',
      component: () => import('@/components/Introduction.vue'),
      meta: {
        title: '本站历史'
      }
    }
  ],
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = "我的博客"
  }
  next()
})

export default router
